package com.ruoyi.web.controller.zhhq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhhq.domain.Cantee;
import com.ruoyi.zhhq.service.ICanteeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 餐厅Controller
 * 
 * @author jieyiming
 * @date 2022-11-03
 */
@RestController
@RequestMapping("/zhhq/cantee")
public class CanteeController extends BaseController
{
    @Autowired
    private ICanteeService canteeService;

    /**
     * 查询餐厅列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cantee:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cantee cantee)
    {
        startPage();
        List<Cantee> list = canteeService.selectCanteeList(cantee);
        return getDataTable(list);
    }
    
    

    /**
     * 导出餐厅列表
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cantee:export')")
    @Log(title = "餐厅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cantee cantee)
    {
        List<Cantee> list = canteeService.selectCanteeList(cantee);
        ExcelUtil<Cantee> util = new ExcelUtil<Cantee>(Cantee.class);
        util.exportExcel(response, list, "餐厅数据");
    }

    /**
     * 获取餐厅详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cantee:query')")
    @GetMapping(value = "/{restauranId}")
    public AjaxResult getInfo(@PathVariable("restauranId") String restauranId)
    {
        return AjaxResult.success(canteeService.selectCanteeByRestauranId(restauranId));
    }

     /**
     * 新增餐厅
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cantee:add')")
    @Log(title = "餐厅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cantee cantee)
    {
    	if(canteeService.selectCanteeByRestauranId(cantee.getRestauranId())!= null) {
    		return AjaxResult.error("餐厅编号已存在，请不要重复添加！");
    	}

    	try {
    		return toAjax(canteeService.insertCantee(cantee));
		} catch (Exception e) {
			// TODO: handle exception
			return AjaxResult.error("添加失败！");
		}

    }

    /**
     * 修改餐厅
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cantee:edit')")
    @Log(title = "餐厅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cantee cantee)
    {
        return toAjax(canteeService.updateCantee(cantee));
    }

    /**
     * 删除餐厅
     */
    @PreAuthorize("@ss.hasPermi('zhhq:cantee:remove')")
    @Log(title = "餐厅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{restauranIds}")
    public AjaxResult remove(@PathVariable String[] restauranIds)
    {
        try {
        	return toAjax(canteeService.deleteCanteeByRestauranIds(restauranIds));
		} catch (Exception e) {
			// TODO: handle exception
			return AjaxResult.error("操作失败！");
		}
    }
}
